//
//  UITapGestureRecognizer+CycleViewGes.m
//  CycleControlFunction
//
//  Created by ddy on 2018/8/6.
//  Copyright © 2018年 ddy. All rights reserved.
//

#import "UITapGestureRecognizer+CycleViewGes.h"
#import <objc/runtime.h>
static const int kTargetKey;
@implementation UITapGestureRecognizer (CycleViewGes)
+ (instancetype)cycle_gestureRecognizerWithActionBlock:(cycleGesBlock)block{
    return [[self alloc]initWithActionBlock:block];
}
- (instancetype)initWithActionBlock:(cycleGesBlock)block{
    self = [self init];
    if(self){
        [self c_addActionBlock:block];
        [self addTarget:self action:@selector(c_invoke:)];
    }
    return self;
}


- (void)c_addActionBlock:(cycleGesBlock)block{
    if(block){
        objc_setAssociatedObject(self, &kTargetKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    }
}

- (void)c_invoke:(id)sender{
    cycleGesBlock block = objc_getAssociatedObject(self, &kTargetKey);
    if(block){
        block(sender);
    }
}
















@end
